package com.ihr360.insurance.service.impl;

import com.ihr360.authority.sharing.annonation.AccessControl;
import com.ihr360.insurance.dao.MandatoryBenefitTemplateReposity;
import com.ihr360.insurance.model.dto.benefits.MandatoryBenefitTemplate;
import com.ihr360.insurance.service.MandatoryBenefitTemplateService;
import com.ihr360.rest.reposity.SimpleRestReposity;
import com.ihr360.rest.service.AbstractSimpleRestServiceImpl;
import com.ihr360.validation.ValidationUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author david.wei
 */
@Service
@AccessControl(disableAll = true)
public class MandatoryBenefitTemplateServiceImpl extends AbstractSimpleRestServiceImpl<MandatoryBenefitTemplate, Long> implements MandatoryBenefitTemplateService {
    @Autowired
    MandatoryBenefitTemplateReposity reposity;

    @Override
    public SimpleRestReposity<MandatoryBenefitTemplate, Long> getSimpleRestReposity() {
        return reposity;
    }

    @Override
    public void updateBenefit(MandatoryBenefitTemplate template) {
        Long id = template.getId();
        MandatoryBenefitTemplate benefitTemplate = reposity.findOne(id);
        ValidationUtils.rejectIfEmpty(benefitTemplate, null, "模板数据不存在，请刷新后重试");
        benefitTemplate.setConfigs(template.getConfigs());
        reposity.save(benefitTemplate);
    }
}
